package com.csw.ems2MavenAjax.controller;

import java.awt.image.BufferedImage;
import java.io.OutputStream;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.csw.ems2MavenAjax.util.SecurityCode;
import com.csw.ems2MavenAjax.util.SecurityImage;

public class CaptchaAction {
	public String execute() throws Exception {
		// ??????????????
		String securityCode = SecurityCode.getSecurityCode();
		/**
		 * ???????????session,��???????????
		 */
		HttpSession session = ServletActionContext.getRequest().getSession();
		session.setAttribute("securityCode", securityCode);

		// ???????????????
		BufferedImage image = SecurityImage.createImage(securityCode);
		// ??????????
		HttpServletResponse response = ServletActionContext.getResponse();
		OutputStream out = response.getOutputStream();
		/**
		 * ??????????? ?????????????? ??????????? ?????? ???????????? ????????
		 */
		ImageIO.write(image, "png", out);

		return null;// ????null?????????
	}
}